package com.example.mobile2021606127cxz0407homework;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

    private Button btnMainChongzhi;
    private RadioGroup radioGroup1;
    private RadioButton radbtnMain1A;
    private RadioButton radbtnMain1B;
    private RadioButton radbtnMain1C;
    private RadioButton radbtnMain1D;
    private RadioGroup radioGroup2;
    private RadioButton radbtnMain2A;
    private RadioButton radbtnMain2B;
    private RadioButton radbtnMain2C;
    private RadioButton radbtnMain2D;
    private RadioGroup radioGroup3;
    private RadioButton radbtnMain3A;
    private RadioButton radbtnMain3B;
    private RadioButton radbtnMain3C;
    private RadioButton radbtnMain3D;
    private RadioGroup radioGroup4;
    private RadioButton radbtnMain4A;
    private RadioButton radbtnMain4B;
    private RadioButton radbtnMain4C;
    private RadioButton radbtnMain4D;
    private Button btnMainTijiao;
    private TextView tvMainZongfen;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();

        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });

        radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });

        radioGroup3.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });

        radioGroup4.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                RadioButton radBtn = findViewById(checkedId);
                radBtn.getText().toString();
                Log.i("RadioButton", radBtn.getText().toString());
            }
        });

        btnMainTijiao.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int No1 = radioGroup1.getCheckedRadioButtonId();
                int No2 = radioGroup2.getCheckedRadioButtonId();
                int No3 = radioGroup3.getCheckedRadioButtonId();
                int No4 = radioGroup4.getCheckedRadioButtonId();

                if (No1 == -1 || No2 == -1 || No3 == -1 || No4 == -1) {
                    Toast.makeText(MainActivity.this, "请作出选择", Toast.LENGTH_SHORT).show();
                } else if (No1 == R.id.radbtn_main_1A && No2 == R.id.radbtn_main_2C && No3 == R.id.radbtn_main_3B && No4 == R.id.radbtn_main_4A) {
                    tvMainZongfen.setText("分数：100分");
                } else if ((No1 == R.id.radbtn_main_1A && No2 == R.id.radbtn_main_2C && No3 == R.id.radbtn_main_3B) || (No1 == R.id.radbtn_main_1A && No2 == R.id.radbtn_main_2C && No4 == R.id.radbtn_main_4A) || (No2 == R.id.radbtn_main_2C && No3 == R.id.radbtn_main_3B && No4 == R.id.radbtn_main_4A)) {
                    tvMainZongfen.setText("分数：75分");
                } else if ((No1 == R.id.radbtn_main_1A && No2 == R.id.radbtn_main_2C) || (No1 == R.id.radbtn_main_1A && No3 == R.id.radbtn_main_3B) || (No1 == R.id.radbtn_main_1A && No4 == R.id.radbtn_main_4A) || (No2 == R.id.radbtn_main_2C && No3 == R.id.radbtn_main_3B) || (No2 == R.id.radbtn_main_2C && No4 == R.id.radbtn_main_4A) || (No3 == R.id.radbtn_main_3B && No4 == R.id.radbtn_main_4A)) {
                    tvMainZongfen.setText("分数：50分");
                } else if ((No1 == R.id.radbtn_main_1A && No2 != R.id.radbtn_main_2C && No3 != R.id.radbtn_main_3B && No4 != R.id.radbtn_main_4A) || (No2 == R.id.radbtn_main_2C && No1 != R.id.radbtn_main_1A && No3 != R.id.radbtn_main_3B && No4 != R.id.radbtn_main_4A) || (No3 == R.id.radbtn_main_3B && No1 != R.id.radbtn_main_1A && No2 != R.id.radbtn_main_2C && No4 != R.id.radbtn_main_4A) || (No4 == R.id.radbtn_main_4A && No1 != R.id.radbtn_main_1A && No2 != R.id.radbtn_main_2C && No3 != R.id.radbtn_main_3B)) {
                    tvMainZongfen.setText("分数：25分");
                } else {
                    tvMainZongfen.setText("分数：0分");
                }


            }
        });
        btnMainChongzhi.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                radbtnMain1A.setChecked(false);
                radbtnMain1B.setChecked(false);
                radbtnMain1C.setChecked(false);
                radbtnMain1D.setChecked(false);
                radbtnMain2A.setChecked(false);
                radbtnMain2B.setChecked(false);
                radbtnMain2C.setChecked(false);
                radbtnMain2D.setChecked(false);
                radbtnMain3A.setChecked(false);
                radbtnMain3B.setChecked(false);
                radbtnMain3C.setChecked(false);
                radbtnMain3D.setChecked(false);
                radbtnMain4A.setChecked(false);
                radbtnMain4B.setChecked(false);
                radbtnMain4C.setChecked(false);
                radbtnMain4D.setChecked(false);
                tvMainZongfen.setText(null);
                Toast.makeText(MainActivity.this, "重置完成", Toast.LENGTH_SHORT).show();
            }
        });
    }

    private void initView() {
        btnMainChongzhi = (Button) findViewById(R.id.btn_main_chongzhi);
        radioGroup1 = (RadioGroup) findViewById(R.id.radioGroup1);
        radbtnMain1A = (RadioButton) findViewById(R.id.radbtn_main_1A);
        radbtnMain1B = (RadioButton) findViewById(R.id.radbtn_main_1B);
        radbtnMain1C = (RadioButton) findViewById(R.id.radbtn_main_1C);
        radbtnMain1D = (RadioButton) findViewById(R.id.radbtn_main_1D);
        radioGroup2 = (RadioGroup) findViewById(R.id.radioGroup2);
        radbtnMain2A = (RadioButton) findViewById(R.id.radbtn_main_2A);
        radbtnMain2B = (RadioButton) findViewById(R.id.radbtn_main_2B);
        radbtnMain2C = (RadioButton) findViewById(R.id.radbtn_main_2C);
        radbtnMain2D = (RadioButton) findViewById(R.id.radbtn_main_2D);
        radioGroup3 = (RadioGroup) findViewById(R.id.radioGroup3);
        radbtnMain3A = (RadioButton) findViewById(R.id.radbtn_main_3A);
        radbtnMain3B = (RadioButton) findViewById(R.id.radbtn_main_3B);
        radbtnMain3C = (RadioButton) findViewById(R.id.radbtn_main_3C);
        radbtnMain3D = (RadioButton) findViewById(R.id.radbtn_main_3D);
        radioGroup4 = (RadioGroup) findViewById(R.id.radioGroup4);
        radbtnMain4A = (RadioButton) findViewById(R.id.radbtn_main_4A);
        radbtnMain4B = (RadioButton) findViewById(R.id.radbtn_main_4B);
        radbtnMain4C = (RadioButton) findViewById(R.id.radbtn_main_4C);
        radbtnMain4D = (RadioButton) findViewById(R.id.radbtn_main_4D);
        btnMainTijiao = (Button) findViewById(R.id.btn_main_tijiao);
        tvMainZongfen = (TextView) findViewById(R.id.tv_main_zongfen);
    }
}